﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QuanLiSinhVien_v01.DAO;
using QuanLiSinhVien_v01.DTO;

namespace QuanLiSinhVien_v01.BUS.Pattern
{
    class InfoOfStudentStrategy: InfoStrategy
    {
        public override Object[] Explore()
        {
            Object[] result;
            SinhVienDao sinhvienDAO = new SinhVienDao();
          //  sinhvienDAO.Search("K");
            result = sinhvienDAO.GetList();
            return result;
        }
        public override Object[] Search(string keyword)
        {
            Object[] result;
            SinhVienDao sinhvienDAO = new SinhVienDao();
            result = sinhvienDAO.Search(keyword);
            return result;
        }
        public override void Update(Object obj)
        {
            SinhVienDto sv = new SinhVienDto();
            DataGridViewRow row = (DataGridViewRow)obj;
            sv.MSSV = row.Cells[0].Value.ToString();
            sv.HoTen = row.Cells[1].Value!=null?row.Cells[1].Value.ToString():"";
            sv.NgaySinh = row.Cells[2].Value!=null?DateTime.Parse(row.Cells[2].Value.ToString()):DateTime.Now;
            sv.MaLop = row.Cells[3].Value!=null?row.Cells[3].Value.ToString():"";
            sv.GhiChu = row.Cells[4].Value!=null?row.Cells[4].Value.ToString():"";
            SinhVienDao sinhvienDAO = new SinhVienDao();
            sinhvienDAO.SinhVien = sv;
            sinhvienDAO.Update();
        }
        public override void Delete(Object obj)
        {
            SinhVienDto sv = new SinhVienDto();
            DataGridViewRow row = (DataGridViewRow)obj;
            sv.MSSV = row.Cells[0].Value.ToString();
            sv.HoTen = row.Cells[1].Value != null ? row.Cells[1].Value.ToString() : "";
            sv.NgaySinh = row.Cells[2].Value != null ? DateTime.Parse(row.Cells[2].Value.ToString()) : DateTime.Now;
            sv.MaLop = row.Cells[3].Value != null ? row.Cells[3].Value.ToString() : "";
            sv.GhiChu = row.Cells[4].Value != null ? row.Cells[4].Value.ToString() : "";
            SinhVienDao sinhvienDAO = new SinhVienDao();
            sinhvienDAO.SinhVien = sv;
            sinhvienDAO.Delete();
        }
        public override void Insert(object obj)
        {
            SinhVienDto sv = new SinhVienDto();
            sv = (SinhVienDto)obj;
            SinhVienDao sinhvienDAO = new SinhVienDao();
            sinhvienDAO.SinhVien = sv;
            sinhvienDAO.Insert();
        }        
    }
}
